package entity

import (
	"fmt"

	"github.com/jinzhu/gorm"
	"shqsoft.cn/pasnj/base"
)

// LrZbProfit 利润预测
type LrZbProfit struct {
	ID   int      `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	NF   int      `gorm:"column:NF"`
	UTID int      `gorm:"column:OrganID"`
	UTNM string   `gorm:"column:OrganName"`
	ZB1  *float64 `gorm:"column:ZB1"`
	ZB2  *float64 `gorm:"column:ZB2"`
	ZB3  *float64 `gorm:"column:ZB3"`
	ZB4  *float64 `gorm:"column:ZB4"`
	ZB5  *float64 `gorm:"column:ZB5"`
	ZB6  *float64 `gorm:"column:ZB6"`
	ZB7  *float64 `gorm:"column:ZB7"`
	ZB8  *float64 `gorm:"column:ZB8"`
	ZB9  *float64 `gorm:"column:ZB9"`
	ZB10 *float64 `gorm:"column:ZB10"`
	ZB11 *float64 `gorm:"column:ZB11"`
	ZB12 *float64 `gorm:"column:ZB12"`
}

//TableName 利润预测
func (LrZbProfit) TableName() string {
	return "T_JHCW_LRYC_NDZB"
}

//BeforeSave 保存前的触发器
func (i *LrZbProfit) BeforeSave(tx *gorm.DB) (err error) {
	sqlstr := "select id from T_Organization where OrganName=?"
	row := tx.Raw(sqlstr, i.UTNM).Row()
	var utid int
	row.Scan(&utid)
	if utid == 0 {
		return fmt.Errorf("指定的部门名称%s在系统中不存在", i.UTNM)
	}
	i.UTID = utid
	return
}

func LrZbProfitEF() base.EntityFunc {
	return func() interface{} {
		entity := LrZbProfit{}
		return &entity
	}
}
func LrZbProfitESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []LrZbProfit
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("LrZbProfit", base.NewDefaultDao(LrZbProfitEF(), LrZbProfitESF(), nil))
}
